import jwt

class Mytoken:
    def __init__(self):
        # 初始化密钥
        self.password='12312312313423wefsdfsdfsef'
    
    def encode_jwt(self,userinfo):
        # 生成jwt          用户信息                   哈希算法
        myjwt = jwt.encode(userinfo,self.password,algorithm='HS256')
        try:
            myjwt = str(myjwt,'utf8')
        except:
            pass
        return myjwt

    def decode(self,myjwt):
        # 
        return jwt.decode(myjwt,self.password,algorithms='HS256')
mytoken = Mytoken()

# 生成
token = mytoken.encode_jwt({'id':1,'username':'jck'})
print(token)

# 解密
print(mytoken.decode(token))

import base64

